
package com.caration.shell.settings;

import android.bluetooth.BluetoothAdapter;

public final class BluetoothManager {
    private static final String SYNC = "sync";
    private static BluetoothManager sInstance;
    private int mState;
    private IconTexture mIconTexture;
//    private RenderRunnable d;
    private BluetoothAdapter mAdapter;

    public static BluetoothManager getInstance() {
        synchronized (SYNC) {
            if (sInstance == null)
                sInstance = new BluetoothManager();
        }
        return sInstance;
    }

    public BluetoothManager() {
        try {
            mAdapter = BluetoothAdapter.getDefaultAdapter();
            mState = mAdapter.getState();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //TODO: 刷新图标纹理
    public final void update(int i) {
//        if (StaticShared.getContext() != null && com.censivn.C3DEngine.a.a() != null) {
//            if (d != null) {
//                com.censivn.C3DEngine.a.a().b(d);
//                d = null;
//            }
//            mState = i;
//            d = new d(this);
//            if (j.a().b())
//                d.autoInvalidate = true;
//            com.censivn.C3DEngine.a.a().a(d);
//            if (mIconTexture != null) {
//                e _tmp = mIconTexture;
//                IconTexture.q();
//            }
//        }
    }

    public final void init(IconTexture iconTexture) {
        mIconTexture = iconTexture;
        updateIcon();
    }

    public final BluetoothAdapter getAdapter() {
        return mAdapter;
    }

    public final void enable() {
        try {
            mAdapter.enable();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public final void disable() {
        try {
            mAdapter.disable();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public final void updateIcon() {
        if (mIconTexture != null)
            switch (mState) {
                default:
                    mIconTexture.setupTexture(0);
                    break;

                case 10: // '\n'
                    mIconTexture.setupTexture(0);
                    break;

                case 11: // '\013'
                    mIconTexture.setupTexture(2);
                    break;

                case 12: // '\f'
                    mIconTexture.setupTexture(1);
                    break;

                case 13: // '\r'
                    mIconTexture.setupTexture(2);
                    break;
            }
    }
}
